

*************************************************************************************************
use  "${Gpath}data\\estimation_sample.dta", clear 
keep if main_sample==1 

gen group=40 if idade<=40 

forvalues i=40(5)95 {
replace group=`i'+5 if idade>`i' & idade<=`i'+5 
}

collapse (mean) m_30d, by(group)

gen x=100*(round(m_30d, 0.001))

twoway (scatter x group), graphregion(color(white) margin(0)) ///
xlabel(40 "<40" 45 "40-45"  50 "45-50" 55 "50-55" 60 "55-60"  65 "60-65"  70 "65-70" 75 "70-75" 80 "75-80" ///
85 "80-85" 90 "85-90" 95 "90-95" 100 "95-100" , labsize(small) ) ///
xscale(r(40 102)) ///
ytitle("30-Day Mortality, %") xtitle("Age group") ///
title("Panel A. 30-Day Mortality by Patient Age", pos(11) size(medium))

graph export "${Gpath}\figures\\mortality_age.pdf", replace 


use  "${Gpath}data\\estimation_sample.dta", clear 
keep if main_sample==1 

gen group=1 if idade<=50 
replace group=2 if idade>50 & idade<=70 
replace group=3 if idade>70


collapse (mean) m_30d, by(group male)
gen x=100*(round(m_30d, 0.001))

g xaxis = group
replace xaxis = group - 0.2 if male==1
replace xaxis = group + 0.2 if male==0

tw (bar x xaxis if male==1, color("0 32 96") barw(0.4)) ///
	(bar x xaxis if male==0, color(cranberry*.8) barw(0.4)) ///
	, title(" ")  ///
	legend(order(1 2 3 4) c(1) ring(0) pos(11) region(color(none)) ///
		lab(1 "Men") lab(2 "Women")) 	graphregion(color(white) margin(0))	xlabel( 1 "<50" 2 "50-70" 3 ">70") ///
		ytitle("30-Day Mortality, %") xtitle("Age group") ///
ylabel(0(2)12) title("Panel B. 30-Day Mortality by Gender", pos(11) size(medium))

graph export "${Gpath}\figures\\mortality_gender.pdf", replace 


use  "${Gpath}data\\estimation_sample.dta", clear 
keep if main_sample==1 

gen group=. 

replace group=1 if substr(diag_princ, 1, 3)== "I20"   /*Angina pectoris*/ 
replace group=2 if diag_princ== "I210" | diag_princ== "I211" | diag_princ== "I212" | diag_princ== "I213"  /*heart attack - ST elevation*/ 
replace group=3 if diag_princ== "I214"   /*heart attack - nonST elevation*/ 
replace group=4 if substr(diag_princ, 1, 3)== "I22"   /*subsequent heart attack*/ 
replace group=5 if group==. /*Other*/ 


collapse (mean) m_30d, by(group)
gen x=100*(round(m_30d, 0.001))

tw (bar x group if group==1, color("126 32 57") barw(0.9) ) ///
	(bar x group if group==2, color("85 111 133") barw(0.9) ) ///
		(bar x group if group==3, color("128 157 97") barw(0.9) ) ///
	(bar x group if group==4, color("169 209 142") barw(0.9) ) ///
	(bar x group if group==5, color("244 203 154") barw(0.9) ) ///
	(function y = 5.6, range(0.5 5.5) color(black) lpattern(dash)) ///
	(pcarrowi 9.2 1 5.7 1, msize(0) ) ///
	, title(" ")  ///
	legend(off) 	graphregion(color(white) margin(0))	xlabel( 1 `" "Angina" "pectoris" "' 2 `"  "Heart attack" "ST-elevation" "' 3 `" "Heart attack" "NonST-elevation" "' ///
	4 `" "Previous" "heart attack" "' 5 "Other", labsize(small)) ///
		ytitle("30-Day Mortality, %") xtitle("") ///
title("Panel C. 30-Day Mortality by Admission Diagnosis", pos(11) size(medium)) ylabel(0(2)10)  text(9.5 1 "Sample Mean") 

graph export "${Gpath}\figures\\mortality_cause.pdf", replace 
	